package cn.kgc.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableWebMvc
public class Swagger3Config {
    @Bean
    public Docket docketDefault(){
        return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }
    @Bean
    public Docket docketGetAll(){
        return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo())
                .apiInfo(apiInfo())
                .groupName("查全部--getAll")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.ant("/getAll/**"))
                .build();
    }
    @Bean
    public Docket docketAddContact(){
        return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo())
                .apiInfo(apiInfo())
                .groupName("添加通讯信息--addContact")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.ant("/add/**"))
                .build();
    }
    @Bean
    public Docket docketgetByName(){
        return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo())
                .apiInfo(apiInfo())
                .groupName("根据姓模糊查询--getByName")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.ant("/getByName/**"))
                .build();
    }
    @Bean
    public Docket docketGetById(){
        return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo())
                .apiInfo(apiInfo())
                .groupName("根据id查询--GetById")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.ant("/GetById/**"))
                .build();
    }
    @Bean
    public Docket docketupd(){
        return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo())
                .apiInfo(apiInfo())
                .groupName("根据id修改--upd")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.ant("/upd/**"))
                .build();
    }
    @Bean
    public Docket docketdel(){
        return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo())
                .apiInfo(apiInfo())
                .groupName("根据id删除--del")
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.ant("/del/**"))
                .build();
    }
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("在线通讯系统")
                .description("这是一个包含添加，修改，删除，按姓名查的通讯系统")
                .version("1.0")
                .contact(new Contact("梁先生","http://kgc.cn", "2907793400@qq.com"))
                .build();
    }
}
